<template>
  <div>
    <article class="card mb-3 shadow-sm" v-for="item in list" :key="item._id">
      <div class="card-body">
        <h4>
          <router-link
            class="text-dark text-decoration-none"
            :to="`/posts/${item._id}`"
          >
            {{ item.title }}
          </router-link>
        </h4>
        <div class="row my-3 align-items-center">
          <div
            class="col-4"
            v-if="item.image && typeof item.image === 'object'"
          >
            <img
              :src="item.image && item.image.fitUrl"
              :alt="item.title"
              class="rounded w-100"
            />
          </div>
          <p class="text-muted" :class="{ 'col-8': item.image }">
            {{ item.excerpt }}
          </p>
        </div>
        <span class="text-muted">{{ item.createdAt }}</span>
      </div>
    </article>
  </div>
</template>
<script lang="ts">
import { defineComponent, PropType } from 'vue'
import { TPostsList } from '@/types/index'
export default defineComponent({
  name: 'PostsList',
  props: {
    list: {
      type: Array as PropType<TPostsList>,
      required: true
    }
  }
})
</script>
